//
//  MineStyle1Cell.swift
//  HappyEat
//
//  Created by ctx2016 on 17/1/9.
//  Copyright © 2017年 陌路是我. All rights reserved.
//

import UIKit

class MineStyle1Cell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUI()
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

}
extension MineStyle1Cell{
    //MAKE:SetUI
    func setUI(){
        let itemWidth:CGFloat = k_Wide/4
        let imageWidth:CGFloat = 22.5
        let names:[String] = ["夺宝记录","幸运记录","我的晒单","活动中心"]
        let imageNames:[String] = ["duobao","xingyun","mine_shaidan","huodong"]
        for i in 0 ..< names.count {
            let bgImageView:UIImageView = UIImageView.init(image: UIImage.init(named: imageNames[i]))
            let titleLabel:UILabel = UILabel.init()
            let leftLabel:UILabel = UILabel.init()
 
            self.contentView.addSubview(bgImageView)
            self.contentView.addSubview(titleLabel)
            self.contentView.addSubview(leftLabel)
            let conTrol:UIControl = UIControl.init()
            self.contentView.addSubview(conTrol)
            conTrol.snp.makeConstraints({ (make) in
                make.left.equalTo(CGFloat(i)*itemWidth)
                make.size.equalTo(CGSize.init(width: itemWidth, height: itemWidth))
                make.top.equalTo(0)
            })
            conTrol.tag = 1000+i
            conTrol.addTarget(self, action: #selector(conTrolAction(_:)), for: .touchUpInside)
            titleLabel.text = names[i]
            titleLabel.textAlignment = .center
            titleLabel.textColor = UIColor.init(red: 101/255.0, green: 102/255.0, blue: 103/255.0, alpha: 1.0)
            titleLabel.font = UIFont.systemFont(ofSize: 14)
            bgImageView.snp.makeConstraints({ (make) in
                make.left.equalTo(((itemWidth - 22.5)/2+(CGFloat(i)*itemWidth)))
                make.width.equalTo(imageWidth)
                make.top.equalTo(15.75)
                make.height.equalTo(imageWidth)
            })
            titleLabel.snp.makeConstraints({ (make) in
                make.left.equalTo(CGFloat(i) * itemWidth)
                make.top.equalTo(bgImageView.snp.bottom).offset(12)
                make.width.equalTo(itemWidth)
                make.height.equalTo(14)
            })
            leftLabel.snp.makeConstraints({ (make) in
                make.left.equalTo(CGFloat(i)*itemWidth)
                make.width.equalTo(0.5)
                make.height.equalTo(80)
                make.top.equalTo(0)
            })
            leftLabel.backgroundColor = .lightGray
            if i == 0{
                leftLabel.isHidden = true
            }
        }
        
        let bottomLabel:UILabel = UILabel.init()
        self.contentView.addSubview(bottomLabel)
        bottomLabel.snp.makeConstraints { (make) in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.height.equalTo(0.5)
            make.bottom.equalTo(0)
        }
        bottomLabel.backgroundColor = .lightGray
    }
    
    func conTrolAction(_ conTrol:UIControl){
        switch conTrol.tag {
        case 1000:
            print("夺宝记录")
            let vc:MineDuobaoController = MineDuobaoController()
            let conTrl:MineController = self.getController(view: self) as! MineController
            conTrl.navigationController?.pushViewController(vc, animated: true)
//            break
        case 1001:
            print("幸运记录")
            let vc:MineLuckController = MineLuckController()
            let conTrl:MineController = self.getController(view: self) as! MineController
            conTrl.navigationController?.pushViewController(vc, animated: true)
//            break
        case 1002:
            print("我的晒单")
            let vc:MineShareDanController = MineShareDanController()
            let conTrl:MineController = self.getController(view: self) as! MineController
            conTrl.navigationController?.pushViewController(vc, animated: true)
//            break
        case 1003:
            print("活动中心")
            let vc:MineActivityController = MineActivityController()
            let conTrol:MineController = self.getController(view: self) as! MineController
            conTrol.navigationController?.pushViewController(vc, animated: true)
//            let vc:MineShareDanController = MineShareDanController()
//            let conTrl:MineController = self.getController(view: self) as! MineController
//            conTrl.navigationController?.pushViewController(vc, animated: true)

//            break
        default:
            print("失败")
            break
        }
    }
}
